import os
import colorama
import sys

def if_folder_exists(folder):
    return os.path.exists(folder)


def if_file_exists(file):
    if not os.path.exists(file):
        return False
    return True


# phrase is sys.args
def concat_phrase(phrase):
    return '_'.join(phrase.split(' '))


def perror(message):
    print(colorama.Fore.RED + message + colorama.Style.RESET_ALL)


def psuccess(message):
    print(colorama.Fore.GREEN + message + colorama.Style.RESET_ALL)


def pinfo(message):
    print(colorama.Fore.WHITE + message + colorama.Style.RESET_ALL)


def get_phrase():
    if len(sys.argv) > 1:
        phrase = ' '.join(sys.argv[1:])
        print(f'phrase: {phrase}')
    else:
        perror('please provide a search phrase')
        sys.exit()
    return phrase.replace(' ', '-')

def check_and_get_background_image(phrase):
    if if_file_exists(f'{phrase}.png'):
        return f'{phrase}.png'
    perror('background image not found')
    sys.exit()

def check_if_video_folder_has_stuff_int_it(phrase):
    if not os.listdir(phrase):
        perror('folder is empty')
        sys.exit()


def check_video_folder(phrase):
    if not if_folder_exists(phrase):
        perror('folder dont exist, please check the phrase')
        sys.exit()
    return phrase
